import 'package:convergence_media/di/di.dart';
import 'package:convergence_media/features/user/entities/news_user_model.dart';
import 'package:isar/isar.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'news_user_repository.g.dart';

@riverpod
NewsUserRepository newsUserRepository(NewsUserRepositoryRef ref) =>
    NewsUserRepository(isar: ref.watch(appIsarProvider));

class NewsUserRepository {
  const NewsUserRepository({
    required Isar isar,
  }) : _isar = isar;

  final Isar _isar;

  Future<Id> saveNewsUser(NewsUserModel newsUserModel) =>
      _isar.writeTxn(() => _isar.newsUserModels.put(newsUserModel));

  Future<NewsUserModel?> readNewsUser(Id id) => _isar.newsUserModels.get(id);
}
